package com.xmx.controller;

import com.xmx.entity.Roles;
import com.xmx.service.IRolesService;
import com.xmx.service.IUser_rolesServices;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * overview：
 * author:ZhaoZH
 * 2023年05月06日 17:35
 */
@Controller
public class RoleController {
    @Autowired
    private IRolesService iRolesService;
    @Autowired
    private IUser_rolesServices iUserRolesServices;

    @RequestMapping("/queryAllRoles")
    public String queryAllRoles(Map map){
        List<Roles> rolesList = iRolesService.queryAllRoles();
        map.put("rolesList",rolesList);
        System.out.println("得到的map:"+rolesList);
        return "Manager/roleManage";
    }
    @RequestMapping("/delteurByrid")
    @ResponseBody
    public String delteurByrid(Integer id){
        //删除中间关系
        iUserRolesServices.deleteur(id);
        //删除角色
        iRolesService.deleterole(id);
        return "1";
    }
    @RequestMapping("/addnewrole")
    public String addnewrole(@RequestParam String rname){
        if(rname != null && !"".equals(rname)){
            System.out.println("变量："+rname);
            Roles roles = new Roles(null, rname, rname);
            System.out.println("对象："+roles);
            iRolesService.addNewRoles(roles);
        }
        return "redirect:queryAllRoles";
    }

}
